<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace addons\config\user\controller;

/**
 * Description of Agreement
 * 用户协议
 * @author shilinqing
 */
class Agreement extends \web\user\controller\AddonUserBase{
    
    public function index(){
        return $this->fetch();
        
    }
    
    /**
     * 用户协议显示
     */
    public function loadList() {
        $m = new \web\common\model\sys\SysOemModel();
        $filter = '1 = 1';
        $total = $m->getTotal($filter);
        $rows = $m->getDataList($this->getPageIndex(), $this->getPageSize(), $filter, '', 'id asc');
        return $this->toDataGrid($total, $rows);
    }

    public function edit_agreement(){
        if (IS_POST) {
            $m = new \web\common\model\sys\SysOemModel();
            $data['agreement'] = htmlspecialchars_decode($this->_post('agreement'));
            $data['update_time'] = NOW_DATETIME;
            if($data['agreement'] == '') {
                return $this->failData('请完善资料');
            }
            $id = input('id');
            $a = $m->save($data,['id'=>$id]);
            if ($a) {

                //添加管理日志
                $this->addLog(self::LOG_EDIT, 'Agreement', $data, 0, '用户协议');

                return $this->successData();
            }else{
                return $this->failData('失败');
            }
        }else{
            $id = intval($this->_get('id'));
            $this->assign('id',$id);
            $this->setLoadDataAction('loadData');

            return $this->fetch();
        }
    }
    public function loadData() {
        $id = $this->_get('id');
        $m = new \web\common\model\sys\SysOemModel();
        $list = $m->where('id',$id)->find();
        $list['agreement'] = htmlspecialchars_decode($list['agreement']);
        return $list;
    }
}
